import {createRouter, createWebHistory} from 'vue-router';
import Home from '../views/Home.vue';
import Docs from '../views/Docs.vue';
import env from "../../env.js";

const routes = [
    {
        path: '/',
        name: 'Home',
        component: Home,
    },
    {
        path: '/docs',
        name: 'Docs',
        component: Docs,
        props: true,
    },
];

const router = createRouter(
    {
        history: createWebHistory(env.VITE_BASE_URL),
        routes,
    }
);

// 全局前置守卫
router.beforeEach(
    (
        to,
        from,
        next
    ) => {
        console.log(`Navigating from ${from.path} to ${to.path}`);
        next();
    }
);

// 全局后置钩子
router.afterEach(
    (
        to,
        from
    ) => {
        console.log(`Navigated from ${from.path} to ${to.path}`);
    }
);

export default router;
   